/**
 * @author: Miss.杨
 * @date: 2025年3月09日 19:13:07
 * @description: 
 */
package com.sheepone.audit.client;

import java.time.LocalDateTime;

import com.sheepone.monitor.audit.core.entities.AuditLogMessage;

/**
 * @author: Miss.杨
 * @date: 2025年3月09日 19:13:07
 * @description:
 */
public class AuditLogMessageContext {
    private final static ThreadLocal<AuditLogMessage> context = new ThreadLocal<AuditLogMessage>();

    public static AuditLogMessage getMessage() {
        // TODO 使用WEBDEV的异常抛出器
        AuditLogMessage message = context.get();
        if (message == null) {
            throw new RuntimeException("AuditLogMessageContext is not set");
        }
        return message;
    }

    public static void newMessage() {
        context.set(new AuditLogMessage());
    }

    public static void clearMessage() {
        context.remove();
    }

    public static void putService(String service) {
        getMessage().setService(service);
    }

    public static void putAppId(String appId) {
        getMessage().setAppId(appId);
    }

    public static void putModule(String module) {
        getMessage().setModule(module);
    }

    public static void putAction(String action) {
        getMessage().setAction(action);
    }

    public static void putRequestTime(LocalDateTime requestTime) {
        getMessage().setRequestTime(requestTime);
    }

    public static void putDuration(Double duration) {
        getMessage().setDuration(duration);
    }

    public static void putStatus(String status) {
        getMessage().setStatus(status);
    }

    public static void putUserId(String userId) {
        getMessage().setUserId(userId);
    }

    public static void putData(Object data) {
        getMessage().setData(data);
    }

    public static void putDataValue(String key, Object value) {
        getMessage().putDataValue(key, value);
    }

}
